Get premium membership and access questions with answers, video lessons as well as revision papers.

Is the following C++ fragment correct? If not, why not? class base { public: virtual int f(int a)=0; //... }; class derived : public base { public: int f(int a, int b) {return...

      

Is the following C++ fragment correct? If not, why not?
class base {
public:
virtual int f(int a)=0;
//...
};
class derived : public base {
public:
int f(int a, int b) {return a*b;}
//...
};

  

Answers


Davis
The fragment is incorrect because the redefinition of a virtual function must have the same return type and type and number of parameters as the original function.In this case the redefinition of f() differs in the number of its parameters.
Githiari answered the question on February 5, 2018 at 10:33


Next: Distinguish between an abstract and polymorphic classes.
Previous: What is unity of command?

View More Computer Studies Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions